const path = require('path');

function resolve(dir) {
    return path.join(__dirname, dir);
}

module.exports = {
    chainWebpack: config => {
        config.resolve.symlinks(true)
        //移除 prefetch 插件
        config.plugins.delete('prefetch')
        //移除 preload 插件
        config.plugins.delete('preload')
        //压缩代码
        config.optimization.minimize(true)
        //分割代码
        config.optimization.splitChunks({
            chunks: 'all'
        })
        //配置别名
        config.resolve.alias
            .set('@', resolve('src'))
            .set('assets', resolve('src/assets'))
            .set('components', resolve('src/components'))
            .set('router', resolve('src/router'))
            .set('utils', resolve('src/utils'))
    },
    lintOnSave: process.env.NODE_ENV === 'development',
    devServer: {
        port: 8081,//端口号
        proxy: {//nodejs代理服务器设置
            '/api': {
                target: 'http://localhost:3000',
                ws: true,
                changeOrigin: true,//开启代理：在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接受请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
                pathRewrite: {
                    '^/api': '/api'
                }
            }
        }
    }
}